#include <iostream>
#include <functional>
#include <time.h>
using namespace std;
int main() {
  auto lambda = [](auto &self, int x) {
    if (x < 2) return 1;
    return self(self, x - 1) + self(self, x - 2);
  };

  // 既然无法自动推导 auto，那就强制确定类型
  // 这样子调用会方便，但是耗时是正确做法的数倍
  function<int(int)> fib = [&fib](int x) {
    if (x < 2) return 1;
    return fib(x - 1) + fib(x - 2);
  };

  clock_t start, end;
  start = clock();
  lambda(lambda, 45);
  end = clock();
  cout << "正确方式，递归耗时: " << end - start << endl;

  start = clock();
  fib(45);
  end = clock();
  cout << "错误方式，递归耗时: " << end - start << endl;

}